//
//  AppDelegate+GDTSplashAd.m
//  JKFuYinProject
//
//  Created by jiukuyinyue on 2017/11/23.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "AppDelegate+GDTSplashAd.h"

@implementation AppDelegate (GDTSplashAd)


#pragma mark - 广点通的广告 要在这些   不要执行下个delegate
-(void)guangDiantong
{
#if DEBUG
    return;
#endif

    //开屏广告初始化并展示代码
    GDTSplashAd *splashG = [[GDTSplashAd alloc] initWithAppkey:@"1106525248" placementId:@"3080528755660322"];
    splashG.delegate = self; //设置代理 //根据iPhone设备不同设置不同背景图
    
    [self setupBGView];///设置背景图片
    
    splashG.backgroundColor = [UIColor clearColor];//设置背景颜色为空白
    
    splashG.fetchDelay = 3; //开发者可以设置开屏拉取时间，超时则放弃展示
    //设置开屏底部自定义LogoView，展示半屏开屏广告

    self.bottomView1 = [[UIView alloc] initWithFrame:CGRectMake(0,ScreenHeight-100, [[UIScreen mainScreen] bounds].size.width, 100)];
    UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gdt_splash_logo"]];
    logo.frame = CGRectMake(0, 0, ScreenWidth, 100);
    [self.bottomView1 addSubview:logo];
    self.bottomView1.backgroundColor = [UIColor whiteColor];
    [splashG loadAdAndShowInWindow:self.window withBottomView: self.bottomView1];
    self.splashGDT1 = splashG;
    [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay:3.0];
}
-(void)delayMethod
{
    self.bgview.hidden = YES;
}
///设置背景图片
- (void)setupBGView {
    UIImageView * bgview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"JKFuYinLaunchScreen"]];
    self.bgview = bgview;
    bgview.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [[[UIApplication sharedApplication].delegate window] addSubview:bgview];
}

//开屏广告关闭回调
- (void)splashAdClosed:(GDTSplashAd *)splashAd
{
    NSLog(@">>>>>>闭回调");
    self.bottomView1 = nil;
    self.splashGDT1 = nil;
    self.bgview.hidden = YES;
}
//开屏广告成功展示
-(void)splashAdSuccessPresentScreen:(GDTSplashAd *)splashAd
{
    self.bgview.hidden = YES;
    NSLog(@">>>>>>成功");
}
//开屏广告展示失败
-(void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error
{
    NSLog(@">>>>>>%@",error);
}
//应用进入后台时回调
- (void)splashAdApplicationWillEnterBackground:(GDTSplashAd *)splashAd
{
    NSLog(@">>>>>>失");
    
}
//开屏广告点击回调
- (void)splashAdClicked:(GDTSplashAd *)splashAd
{
    NSLog(@">>>>>>开屏广告点击回调");
    
}

@end
